//纸张尺寸信息
const PAPER_INFO = {
  A5: {size:'210*140',name:'A5',a3mutiple:0.25},
  A4: {size:'285*210',name:'A4',a3mutiple:0.5},
  A3: {size:'420*285',name:'A3',a3mutiple:1},
  A3L: {size:'210*570',name:'长A3'},
  A2S: {size:'285*630',name:'小A2'},
  A2: {size:'420*570',name:'A2'},
  A2L: {size:'285*840',name:'长A2'},
  A1: {size:'840*570',name:'A1'},
}

const PAGE_SIZE = [
  {size:'210*140',name:'A5',a5ratios:1},
  {size:'285*210',name:'A4',a5ratios:2},
  {size:'420*285',name:'A3',a5ratios:4},
  {size:'570*420',name:'A2',a5ratios:8},
  {size:'840*570',name:'A1',a5ratios:16}
]

const SINGLE_PAGE_SIZE = {
  A6:{
    name:'A6',size:'100*140',a4radio:0.25,a5radio:0.5,code:'A6'
  },
  A5:{
    name:'A5',size:'210*140',a4radio:0.5,a5radio:1,code:'A5'
  },
  A4:{
    name:'A4',size:'285*210',a4radio:1,a5radio:2,code:'A4'
  },
  A3:{
    name:'A3',size:'420*285',a4radio:2,a5radio:4,code:'A3'
  },
  LA3:{
    name:'长A3',size:'210*570',a4radio:2,a5radio:4,code:'LA3'
  },
  TA4:{
    name:'3A4',size:'210*630',a4radio:3,a5radio:6,code:'TA4'
  },
  A2:{
    name:'A2',size:'420*570',a4radio:4,a5radio:8,code:'A2'
  },
  LA2:{
    name:'长A2',size:'285*840',a4radio:4,a5radio:8,code:'LA2'
  },
  A1:{
    name:'A1',size:'840*570',a4radio:8,a5radio:16,code:'A1'
  }
}

export default {
  //判断纸张是否大于，格式：'285*210'
  ifPageAreaBiggerThan(a1,a2){
    let a1_length = parseInt(a1.split('*')[0])
    let a1_width = parseInt(a1.split('*')[1])
    let a2_length = parseInt(a2.split('*')[0])
    let a2_width = parseInt(a2.split('*')[1])
    let biggerFlag1,biggerFlag2 = false
    if((a1_length > a2_length) || (a1_width > a2_width)){
      biggerFlag1 = true
    }
    if((a1_width > a2_length) || (a1_length > a2_width)){
      biggerFlag2 = true
    }
    return (biggerFlag1 & biggerFlag2)
  },

  //判断尺寸范围
  getPageSizeRange(size){
    let ret =  undefined
    Object.keys(PAPER_INFO).forEach(key => {
      // console.log(size+'---' + PAPER_INFO[key].size + '---' + this.ifPageAreaBiggerThan(size,PAPER_INFO[key].size))
      if(!this.ifPageAreaBiggerThan(size,PAPER_INFO[key].size)){
        if(!ret){
          ret =  PAPER_INFO[key]
        }
      }
    })
    return ret
  },

  //尺寸拼版数量
  getCountMakeupInSize(size,baseSize){
    let arr1 = size.split("*")
    let arr2 = baseSize.split("*")
    return this.caculateCountPerPage(parseInt(arr2[0]),parseInt(arr2[1]),parseInt(arr1[0]),parseInt(arr1[1]))
  },

  caculateCountPerPage(len,width,customLen,customWidth){
    let a = 0
    let b = 0
    if(len >= customLen && width >= customWidth){
      a = parseInt(len / customLen) * parseInt(width / customWidth)
    }

    if(len >= customWidth && width >= customLen){
      b = parseInt(len / customWidth) * parseInt(width / customLen)
    }

    return a >= b ? a : b
  },

  PAPER_INFO,
  PAGE_SIZE,
  SINGLE_PAGE_SIZE
}
